<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺id" prop="storeId">
        <el-input
          v-model="queryParams.storeId"
          placeholder="请输入店铺id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" ref="toolbar">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          @click="handleAdd"
          v-hasPermi="['business:wholeStationIndicators:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:wholeStationIndicators:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:wholeStationIndicators:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExport"
          v-hasPermi="['business:wholeStationIndicators:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <div ref="divTable" :style="'height:' + divHeight + 'px'">
      <el-table v-loading="loading" :data="wholeStationIndicatorsList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="id" align="center" prop="id" />
        <el-table-column label="店铺id" align="center" prop="storeId" />
        <el-table-column label="统计日期" align="center" prop="statDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.statDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="主体id" align="center" prop="mainBodyId" />
        <el-table-column label="主体类型" align="center" prop="mainBodyType" />
        <el-table-column label="主体名称" align="center" prop="mainBodyName" />
        <el-table-column label="花费" align="center" prop="costAmount" />
        <el-table-column label="总成交金额" align="center" prop="totalTransactionAmount" />
        <el-table-column label="实际投产比" align="center" prop="actualProductionRatio" />
        <el-table-column label="展现量" align="center" prop="impressions" />
        <el-table-column label="点击量" align="center" prop="hits" />
        <el-table-column label="点击率" align="center" prop="clickRate" />
        <el-table-column label="平均点击花费" align="center" prop="averageClickCost" />
        <el-table-column label="千次展现花费" align="center" prop="thousandShowCost" />
        <el-table-column label="总成交笔数" align="center" prop="totalTransactionsNumber" />
        <el-table-column label="点击转化率" align="center" prop="clickConversionRate" />
        <el-table-column label="总购物车数" align="center" prop="totalShopCartNumber" />
        <el-table-column label="收藏宝贝数" align="center" prop="collectTreasureNumber" />
        <el-table-column label="宝贝收藏加购数" align="center" prop="collectTreasureBuyNumber" />
        <el-table-column label="助推展现量" align="center" prop="boostShowNumber" />
        <el-table-column label="助推带动点击量" align="center" prop="boostClickNumber" />
        <el-table-column label="直接成交金额" align="center" prop="directBusinessAmount" />
        <el-table-column label="直接成交笔数" align="center" prop="directBusinessNumber" />
        <el-table-column label="总预售成交额" align="center" prop="totalPreSaleAmount" />
        <el-table-column label="总预售成笔数" align="center" prop="totalPreSaleNumber" />
        <el-table-column label="直接预售成交额" align="center" prop="directPreSaleAmount" />
        <el-table-column label="直接预售成笔数" align="center" prop="directPreSaleNumber" />
        <el-table-column label="含预售投产比" align="center" prop="preSaleRatio" />
        <el-table-column label="状态 正常：NORMAL 删除：DELETED 锁定：LOCKED" align="center" prop="status" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['business:wholeStationIndicators:edit']"
            >修改</el-button>
            <el-button
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['business:wholeStationIndicators:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="total>0"
          :pageRefs="this.$refs"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
      />
    </div>
    <!-- 添加或修改全站推指标数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="店铺id" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="统计日期" prop="statDate">
          <el-date-picker clearable
            v-model="form.statDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择统计日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="主体id" prop="mainBodyId">
          <el-input v-model="form.mainBodyId" placeholder="请输入主体id" />
        </el-form-item>
        <el-form-item label="主体名称" prop="mainBodyName">
          <el-input v-model="form.mainBodyName" placeholder="请输入主体名称" />
        </el-form-item>
        <el-form-item label="花费" prop="costAmount">
          <el-input v-model="form.costAmount" placeholder="请输入花费" />
        </el-form-item>
        <el-form-item label="总成交金额" prop="totalTransactionAmount">
          <el-input v-model="form.totalTransactionAmount" placeholder="请输入总成交金额" />
        </el-form-item>
        <el-form-item label="实际投产比" prop="actualProductionRatio">
          <el-input v-model="form.actualProductionRatio" placeholder="请输入实际投产比" />
        </el-form-item>
        <el-form-item label="展现量" prop="impressions">
          <el-input v-model="form.impressions" placeholder="请输入展现量" />
        </el-form-item>
        <el-form-item label="点击量" prop="hits">
          <el-input v-model="form.hits" placeholder="请输入点击量" />
        </el-form-item>
        <el-form-item label="点击率" prop="clickRate">
          <el-input v-model="form.clickRate" placeholder="请输入点击率" />
        </el-form-item>
        <el-form-item label="平均点击花费" prop="averageClickCost">
          <el-input v-model="form.averageClickCost" placeholder="请输入平均点击花费" />
        </el-form-item>
        <el-form-item label="千次展现花费" prop="thousandShowCost">
          <el-input v-model="form.thousandShowCost" placeholder="请输入千次展现花费" />
        </el-form-item>
        <el-form-item label="总成交笔数" prop="totalTransactionsNumber">
          <el-input v-model="form.totalTransactionsNumber" placeholder="请输入总成交笔数" />
        </el-form-item>
        <el-form-item label="点击转化率" prop="clickConversionRate">
          <el-input v-model="form.clickConversionRate" placeholder="请输入点击转化率" />
        </el-form-item>
        <el-form-item label="总购物车数" prop="totalShopCartNumber">
          <el-input v-model="form.totalShopCartNumber" placeholder="请输入总购物车数" />
        </el-form-item>
        <el-form-item label="收藏宝贝数" prop="collectTreasureNumber">
          <el-input v-model="form.collectTreasureNumber" placeholder="请输入收藏宝贝数" />
        </el-form-item>
        <el-form-item label="宝贝收藏加购数" prop="collectTreasureBuyNumber">
          <el-input v-model="form.collectTreasureBuyNumber" placeholder="请输入宝贝收藏加购数" />
        </el-form-item>
        <el-form-item label="助推展现量" prop="boostShowNumber">
          <el-input v-model="form.boostShowNumber" placeholder="请输入助推展现量" />
        </el-form-item>
        <el-form-item label="助推带动点击量" prop="boostClickNumber">
          <el-input v-model="form.boostClickNumber" placeholder="请输入助推带动点击量" />
        </el-form-item>
        <el-form-item label="直接成交金额" prop="directBusinessAmount">
          <el-input v-model="form.directBusinessAmount" placeholder="请输入直接成交金额" />
        </el-form-item>
        <el-form-item label="直接成交笔数" prop="directBusinessNumber">
          <el-input v-model="form.directBusinessNumber" placeholder="请输入直接成交笔数" />
        </el-form-item>
        <el-form-item label="总预售成交额" prop="totalPreSaleAmount">
          <el-input v-model="form.totalPreSaleAmount" placeholder="请输入总预售成交额" />
        </el-form-item>
        <el-form-item label="总预售成笔数" prop="totalPreSaleNumber">
          <el-input v-model="form.totalPreSaleNumber" placeholder="请输入总预售成笔数" />
        </el-form-item>
        <el-form-item label="直接预售成交额" prop="directPreSaleAmount">
          <el-input v-model="form.directPreSaleAmount" placeholder="请输入直接预售成交额" />
        </el-form-item>
        <el-form-item label="直接预售成笔数" prop="directPreSaleNumber">
          <el-input v-model="form.directPreSaleNumber" placeholder="请输入直接预售成笔数" />
        </el-form-item>
        <el-form-item label="含预售投产比" prop="preSaleRatio">
          <el-input v-model="form.preSaleRatio" placeholder="请输入含预售投产比" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWholeStationIndicators, getWholeStationIndicators, delWholeStationIndicators, addWholeStationIndicators, updateWholeStationIndicators, exportExcel } from "@/api/business/wholeStationIndicators";
import ResizeMixin from "@/layout/mixin/ResizeHandler";

export default {
  name: "WholeStationIndicators",
  mixins: [ResizeMixin],
  data() {
    return {
      // div高度
      divHeight: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 全站推指标数据表格数据
      wholeStationIndicatorsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeId: null,
        statDate: null,
        mainBodyId: null,
        mainBodyType: null,
        mainBodyName: null,
        costAmount: null,
        totalTransactionAmount: null,
        actualProductionRatio: null,
        impressions: null,
        hits: null,
        clickRate: null,
        averageClickCost: null,
        thousandShowCost: null,
        totalTransactionsNumber: null,
        clickConversionRate: null,
        totalShopCartNumber: null,
        collectTreasureNumber: null,
        collectTreasureBuyNumber: null,
        boostShowNumber: null,
        boostClickNumber: null,
        directBusinessAmount: null,
        directBusinessNumber: null,
        totalPreSaleAmount: null,
        totalPreSaleNumber: null,
        directPreSaleAmount: null,
        directPreSaleNumber: null,
        preSaleRatio: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询全站推指标数据列表 */
    getList() {
      this.loading = true;
      listWholeStationIndicators(this.queryParams).then(response => {
        this.wholeStationIndicatorsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storeId: null,
        statDate: null,
        mainBodyId: null,
        mainBodyType: null,
        mainBodyName: null,
        costAmount: null,
        totalTransactionAmount: null,
        actualProductionRatio: null,
        impressions: null,
        hits: null,
        clickRate: null,
        averageClickCost: null,
        thousandShowCost: null,
        totalTransactionsNumber: null,
        clickConversionRate: null,
        totalShopCartNumber: null,
        collectTreasureNumber: null,
        collectTreasureBuyNumber: null,
        boostShowNumber: null,
        boostClickNumber: null,
        directBusinessAmount: null,
        directBusinessNumber: null,
        totalPreSaleAmount: null,
        totalPreSaleNumber: null,
        directPreSaleAmount: null,
        directPreSaleNumber: null,
        preSaleRatio: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        status: null,
        remark: null
      };
      this.$resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加全站推指标数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWholeStationIndicators(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改全站推指标数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWholeStationIndicators(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWholeStationIndicators(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除全站推指标数据编号为"' + ids + '"的数据项？').then(function() {
        return delWholeStationIndicators(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      exportExcel(this.queryParams)
    }
  }
};
</script>
